# Copyright (c) 2008-2009 Mikhail Chernov 
#
# This file is part of dcExplorer.
#
# dcExplorer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# dcExplorer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dcExplorer.  If not, see <http://www.gnu.org/licenses/>.

package dcExplorer::view::fleet::Simple;
use strict;
use canvas::Color;

sub new 
{
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self  = {};
	bless ($self, $class);
	return $self;
}

sub transformControlled
{
	my $self = shift;
	my $fleet = shift;	
	my $empire = shift;
	
	my $mil = 0;
	$mil += ($_->getProp('laser_damage') || 0) + ($_->getProp('bomb_damage') || 0) 
		foreach map { $empire->designHouse()->getPrototypeByID($_->getProp('building_id')) } 
			grep { defined($_->getProp('is_transportable')) && $_->getProp('is_transportable') == 0 } $fleet->getAllUnits();
	my @rgb = $mil ? (255, 0, 0) : (255, 255, 255);
	
	@rgb = map { int($_ / 2) } @rgb if ($fleet->getProp('shared'));

	my $fg = dcExplorer::canvas::Color->new(@rgb);

	my $w = 0;	
	$w += $_->getProp('weight') || 0
		foreach grep { defined($_->getProp('is_transportable')) && $_->getProp('is_transportable') == 0 } $fleet->getAllUnits();
	my $penSize = int($w > 500) + int($w > 5000);

	return ($fg, $penSize);
}

sub transformEnemy
{
	my $self = shift;
	my $fleet = shift;	
	my $empire = shift;
	
	my $fg = defined($fleet->getProp('relation_nature')) ? 
		$fleet->getProp('relation_nature') == 0 ? 
			dcExplorer::canvas::Color->new(255, 0, 0) : 
			dcExplorer::canvas::Color->new(127, 127, 127) :
		dcExplorer::canvas::Color->new(255, 255, 0);

	my $penSize = int($fleet->getProp('sum_weight') > 500) + int($fleet->getProp('sum_weight') > 5000);

	return ($fg, $penSize);
}

1;
